<?php include "antet.php"; include "func.php";

if (isset($_SESSION["user"][0]))
{
	$towns=towns($_SESSION["user"][0]);
	//$town=town($_SESSION["user"][0]);
	$twnCount=count($towns);

}
else {header('Location: login.php'); die();}
kepala($title." - ".$lang["towns"]);
?>
<?php
$output = BlankHeader("", "", $lang["towns"],"Cities in your empire.","report.png");
$thelist = '';
//d($towns );
if ($towns  == "")
			{
				$thelist .= '
				<a class="btn btn-success btn-block" href="create.php?is_cap=1">'.$lang["createTown"].'</a>
				We need a capital city to start, choose a location thats far away from other player for future empire growth.
				<br/>Commonly, a new empire prefer to start near a water terrain.<br/>';
			}
		else
			{
			// map depends on this db data
			// 2 - housing
			// 3 - farm/grain mill
			// 4 - lumber
			// 5 - mine
			// 6 - farmcow
			$thelist = '<div class="btn-group btn-group-sm btn-group-justified">';
			//$thelist .= "<a class='btn btn-default' href='create.php?is_cap=7'>".$lang['createTown']."</a>";
			$thelist .= "<a class='btn btn-default' href='create.php?is_cap=2'>New Housing</a>";
			$thelist .= "<a class='btn btn-default' href='create.php?is_cap=3'>New Grain Mill</a>";
			$thelist .= "<a class='btn btn-default' href='create.php?is_cap=4'>New Lumber Mill</a>";
			$thelist .= "<a class='btn btn-default' href='create.php?is_cap=5'>New Stone Quarry</a>";
			$thelist .= "<a class='btn btn-default' href='create.php?is_cap=6'>New Mining Site</a>";
			$thelist .= '</div>';
			$thelist .= '<br/><table class="table table-bordered table-hover">
			<thead><tr>
				<th>'.$lang["townName"].'</th>
				<th>'.$lang["population"].'</th>
				<th>'.$lang["coords"].'</th>
				<th>'.$lang["townEdit"].'</th>
				<th>'.$lang["abandon"].'</th>
				<th>'.$lang["purge"].'</th>
			</tr></thead><tbody>';
			for ($i=0; $i<$twnCount; $i++)
				{
				// $town=town_xy($towns[$i][0]);
				$iscapital = ">";
				$capital  = '';
				if($towns[$i][4] == '1')
					{
					$iscapital = ' class="success">';
					$capital = ' class="label label-success" ';
					}
				$thelist .= '
					<tr'.$iscapital.'
						<td><a '.$capital .' href="town.php?town='.$towns[$i][0].'">'.$towns[$i][2].'</a> </td>
						<td><span class="badge badge-primary">'.$towns[$i][3].'</span></td>
						<td><a class="q_link" href="map.php?x='.$towns[$i][23].'&y='.$towns[$i][24].'">('.$towns[$i][23].', '.$towns[$i][24].')</a></td>
						<td><a class="btn btn-success btn-xs" href="town_edit.php?town='.$towns[$i][0].'">'.$lang["townEdit"].'</a></td>
						<td><a class="btn btn-warning btn-xs" href="abandon.php?town='.$towns[$i][0].'">'.$lang["abandon"].'</a></td>
						<td><a class="btn btn-danger btn-xs" href="purge.php?town='.$towns[$i][0].'">'.$lang["purge"].'</a></td>
					</tr>';
					//  <td><a class="q_link" href="town.php?town='.$towns[$i][0].'&v=1">flash</a></td>
				}
		$thelist .= '</tbody></table>';
		} // town is 0
			$form = '<a class="btn btn-warning btn-block" href="ch_capital.php">'.$lang['changeCap'].'</a>';
	$output .= PageSection("townlist", 12, $lang["towns"], $thelist, $form);
		$output .= ads(1,"bottom");
		$output .= about(""); 
		echo $output;
?>
